<?php
/**
 * Created by 绵阳市碳素云信息技术有限责任公司.
 * User: castle
 * Date: 2015/06/06
 * Time: 10:13
 */
header("content-type:text/html;charset = utf-8");
function operation()
{
    $a = 15;
    $b = 3;
    echo "四则运算"."<br>";
    echo "a+b = ".($a+$b)."<br>";
    echo "a-b = ".($a-$b)."<br>";
    echo "a*b = ".($a*$b)."<br>";
    echo "a/b = ".($a/$b)."<br>";
}
function traverse($people){
    foreach($people as $i=> $i_value)
    {
        echo "键 = ".$i.","."值 = ".$i_value."<br>";
    }
}
function mergeArray($people ,$others){

}

//function arrayUintersect($people ,$others){
//
//    $num =  compare(count($people),count($others));
//    $k = 0;
//    echo  $num;
//    for($i = 0;$i <$num;$i++) {
//        echo  $people[0];
////        if(compare($people[$i],$others[$i]) == 0)
////        $allpeople[$k++] = $people[$i];
////        echo  $people[$i];
//        echo  compare($i,$others[$i]);
//    }
//}
function compare($a,$b)
{
    if ($a===$b)
    {
        return 0;
    }
    return ($a>$b)?1:-1;
}
function arrayOperation(){
    $people = array("张三"=>"1","李四"=>"2","王五"=>"5","杨怡"=>"4","赵六"=>"6","东"=>"3","西"=>"7");
    $others = array("王五"=>"11","杨怡"=>"9","东"=>"13","南"=>"8","北"=>"10","西"=>"12");
    echo "PHP 数组的操作<br>";
    echo "创建两个数组并遍历 <br>";
    echo "数组People :<br>";
    traverse($people);
    echo "数组Others :<br>";
    traverse($others);
    echo "合并: <br>";
    traverse(array_merge($people,$others));
    echo "递归 :<br>";
    traverse(array_merge_recursive($people,$others));
    echo "差集 :<br>";
    $result = array_udiff($people,$others,"compare");
    traverse($result);
    echo "交集 只比较键名:<br>";
    $result = array_intersect_key($people,$others);
    traverse($result);
    echo "并集 :<br>";
    $result = $people + $others;
    traverse($result);
}

function stringOperation(){
    $str = "http://www.w3cschool.cc/php/php-string.html";
    echo "字符长度 <br>";
    echo strlen($str);
    echo "字符串位置查找<br>：";
    echo "找到html的位置在字符串".$str."第".strpos($str,"html")."位";
}
operation();
arrayOperation();

?>